package root.action;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Demo3
 */
//@WebServlet("/Demo3")
public class Demo3 extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String servlet_var = getInitParameter("var1");
		System.out.println(servlet_var);
		
		ServletContext app = request.getServletContext();
		String application_var = app.getInitParameter("var2");
		System.out.println(application_var);
		
		
		Integer count = null;
		synchronized (Demo3.class) {
			if(app.getAttribute("count")==null) {
				count = 0;
			}else {
				count = (Integer) app.getAttribute("count");
			}
			app.setAttribute("count", ++count);
		}
		response.getWriter().write("count: "+count);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
